<!--
    文档监控页面
-->
<!DOCTYPE html>
<html>
<head>
    <title>ManaGement PlatForm</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <meta name="_csrf" content="2a049f84-561c-44bf-ae25-f24fbf78b313">
    <meta name="_csrf_header" content="X-CSRF-TOKEN">
    <script src="/wedding_admin/js/jquery.min.js"></script>
    <script src="/wedding_admin/js/kendo/kendo.all.min.js"></script>
    <script src="/wedding_admin/js/jszip.min.js"></script>
    <script src="/wedding_admin/js/um/respond.min.js"></script>
    <script src="/wedding_admin/js/um/es5-shim.min.js"></script>

    <script src="/wedding_admin/js/kendo/kendo.culture.zh-CN.js"></script>
    <script src="/wedding_admin/js/kendo/kendo.messages.zh-CN.js"></script>
    <script src="/wedding_admin/js/kendo/kendo.hap.js?v=20180330"></script>
    <script src="/wedding_admin/js/um/moment.min.js"></script>
    <script src="/wedding_admin/js/um/daterangepicker.js"></script>


    <script src="/wedding_admin/js/vue_table/vue.min.js"></script>
    <script src="/wedding_admin/js/vue_table/vue-validator.min.js"></script>


    <script src="/wedding_admin/js/bootstrap/moment.min.js"></script>
    <script src="/wedding_admin/js/bootstrap/moment-with-locales.js"></script>
    <link href="/wedding_admin/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <script src="/wedding_admin/js/bootstrap/bootstrap-datetimepicker.min.js"></script>

    <script src="/wedding_admin/js/layui/layui.js"></script>
    <link href="/wedding_admin//css/layui.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/css/ztree/css/metroStyle/metroStyle.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/statics/css/simple-line-icons.min.css" rel="stylesheet" type="text/css">
    <link href="/wedding_admin/css/um/kendo.common-bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/css/um/kendo.bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/css/um/kendo.hap.css" rel="stylesheet" type="text/css"/>
    <link href="/wedding_admin/css/um/daterangepicker.css" rel="stylesheet">


</head>

<style>
    .form-group > .col-sm-4 {
        padding: 0;
    }


    .more-condition-search .fa {
        margin-left: 5px;
    }

    .panel-body {
        padding-bottom: 5px;
    }
</style>
<body>
<script type="text/javascript">


</script>

<div id="rrapp" v-cloak>
    <div class="deal_info_box pb15" id="deal_info_box" style="display:none">
        <form class="form-horizontal" id="myForm">
            <div class="pull-center" id="query-form" style="padding-bottom:10px;">
                <div class="panel-body">
                    <div class="form-group search-condition-1">


                        <div class="col-sm-4">
                            <label class="col-sm-4 control-label">文档编号</label>
                            <div class="col-sm-8">
                                <input type="text" id="wdbh" name="wdbh"
                                       style="width:100%"
                                       class="k-textbox">
                            </div>
                        </div>


                        <div class="col-sm-4">
                            <label class="col-sm-4 control-label">文档标题</label>
                            <div class="col-sm-8">
                                <input type="text" id="wdbt" name="wdml"
                                       style="width:100%"
                                       class="k-textbox">
                            </div>
                        </div>


                        <div class="col-sm-4">
                            <label class="col-sm-4 control-label">文档创建者</label>
                            <div class="col-sm-6">
                                <input type="text" id="username" name="serviceName"
                                       style="width:100%"
                                       class="k-textbox">
                            </div>
                        </div>


                        <div class="col-sm-4" style="margin-top:10px;">
                            <label class="col-sm-4 control-label">起始日期</label>
                            <div class="col-sm-8">
                                <div class='input-group date' id='datetimepicker1'>
                                    <input type='text' id="cjrq" class="form-control"/>
                                    <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                                </div>
                                <div class='input-group date' id='datetimepicker2'>
                                    <input type='text' id="jsrq" class="form-control"/>
                                    <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-4" style="margin-top:10px;">
                            <label class="col-sm-4 control-label">文档状态</label>
                            <div class="col-sm-6">
                                <select name="quiz2" id="wdzt" lay-filter="aihao" style="width:80%;height: 30px">
                                    <option value="1" style="width:100%;height: 50px" selected="">正常</option>
                                    <option value="2" style="width:100%;height: 50px">待发布</option>
                                    <option value="4" style="width:50%;height: 50px">作废</option>
                                </select>

                            </div>
                        </div>


                        <div class="col-sm-4" style="margin-top:10px;">
                            <label class="col-sm-4 control-label"></label>
                            <div class="col-sm-8">
                             <span id="btnSearch" class="btn btn-primary" style="float:left;margin-right:5px;"
                                   data-bind="click:selectList"
                                   type="button"><i class="fa fa-search" style="margin-right:3px;"></i>查询</span>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="layerDemo" style="margin-bottom: 0;">
        <div class="layui-btn-container" style="padding-bottom:10px;margin-top: 10px">
            <button type="button" @click="publishDoc" class="layui-btn">发布文档</button>
            <button type="button" @click="cancelDoc" class="layui-btn layui-btn-warm">作废文档</button>
            <button type="button" @click="archiveDoc" class="layui-btn layui-btn-normal">重新启用作废文档</button>
            <button type="button" @click="deleteDoc" class="layui-btn layui-btn-danger">删除文档</button>
            <button type="button" class="layui-btn layui-btn-primary" id="detailmain_a">高级搜索</button>

        </div>
    </div>

    <div style="clear:both">
        <div id="grid"></div>
    </div>


</div>
<script>
    /*时间控件*/
    $(function () {


        var picker1 = $('#datetimepicker1').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            locale: moment.locale('zh-cn'),


        });

        var picker2 = $('#datetimepicker2').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            locale: moment.locale('zh-cn'),

        });

        //动态设置最小值
        picker1.on('dp.change', function (e) {
            picker2.data('DateTimePicker').minDate(e.date);
        });
        //动态设置最大值
        picker2.on('dp.change', function (e) {
            picker1.data('DateTimePicker').maxDate(e.date);
        });
    });


    $(function view_details_click() {
        $("#detailmain_a").click(function () {
            if ($("#deal_info_box").is(":hidden")) {
                $('#deal_info_box').slideDown('slow');
                $(this).text("收起︿");
            } else {
                $('#deal_info_box').slideUp('slow');
                $(this).text("展开﹀");

            }
        });
    });


</script>

<script>


    var vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            title: null,

        },
        methods: {
            getMenu: function (menuId) {


            },
            publishDoc: function () {//发布
                var grid = $("#grid").data("kendoGrid");
                var checked = grid.selectedDataItems();

                if (grid.selectedDataItems().length == 0) {
                    alert("请选择一条记录");
                    return;
                }
                var arr1 = new Array();
                for (var i = 0; i <grid.selectedDataItems().length; i++) {

                    if (JSON.stringify(checked[i]["delFlag"])!=2){
                        alert("存在不是待发布文档，无法发布");
                        return;
                    }
                    arr1.push(checked[i]["id"])
                }

                $.ajax({
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    type: "POST",
                    url: "/wedding_admin/sys/sysdocument/publishDoc",
                    data: JSON.stringify(arr1),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功');
                            var grid = $("#grid").data("kendoGrid");//重新读取数据库写法  刷新页面·
                            grid.dataSource.read();

                        } else {
                            alert(r.msg);
                        }
                    }
                });

            },
            cancelDoc: function () {//作废
                var grid = $("#grid").data("kendoGrid");
                var checked = grid.selectedDataItems();

                if (grid.selectedDataItems().length == 0) {
                    alert("请选择一条记录");
                    return;
                }

                var arr1 = new Array();
                for (var i = 0; i <grid.selectedDataItems().length; i++) {

                    if (JSON.stringify(checked[i]["delFlag"])==4){
                        alert("存在已作废文档，无法作废");
                        return;
                    }
                    arr1.push(checked[i]["id"])
                }

                $.ajax({
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    type: "POST",
                    url: "/wedding_admin/sys/sysdocument/cancelDoc",
                    data: JSON.stringify(arr1),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功');
                            var grid = $("#grid").data("kendoGrid");//重新读取数据库写法  刷新页面·
                            grid.dataSource.read();

                        } else {
                            alert(r.msg);
                        }
                    }
                });




            },
            archiveDoc: function () {//重新启用状态为发布
                var grid = $("#grid").data("kendoGrid");
                var checked = grid.selectedDataItems();

                if (grid.selectedDataItems().length == 0) {
                    alert("请选择一条记录");
                    return;
                }
                var arr1 = new Array();
                for (var i = 0; i <grid.selectedDataItems().length; i++) {

                    if (JSON.stringify(checked[i]["delFlag"])!=4){
                        alert("存在不是作废文档，无法启用");
                        return;
                    }
                    arr1.push(checked[i]["id"])
                }

                $.ajax({
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    type: "POST",
                    url: "/wedding_admin/sys/sysdocument/publishDoc",
                    data: JSON.stringify(arr1),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功');
                            var grid = $("#grid").data("kendoGrid");//重新读取数据库写法  刷新页面·
                            grid.dataSource.read();

                        } else {
                            alert(r.msg);
                        }
                    }
                });

            },
            deleteDoc: function () {//删除
                var grid = $("#grid").data("kendoGrid");
                var checked = grid.selectedDataItems();

                if (grid.selectedDataItems().length == 0) {
                    alert("请选择一条记录");
                    return;
                }

                var arr1 = new Array();
                for (var i = 0; i <grid.selectedDataItems().length; i++) {
                    arr1.push(checked[i]["id"])
                }
                var rs = confirm('确定要删除选中的记录？');
                if (rs) {

                    $.ajax({
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        type: "POST",
                        url: "/wedding_admin/sys/sysdocument/deleteDoc",
                        data: JSON.stringify(arr1),
                        success: function (r) {
                            if (r.code === 0) {
                                alert('操作成功');
                                var grid = $("#grid").data("kendoGrid");//重新读取数据库写法  刷新页面·
                                grid.dataSource.read();

                            } else {
                                alert(r.msg);
                            }
                        }
                    });

                }
            },

            reload: function () {
                vm.showList = true;
                Menu.table.refresh();
            }


        }
    });

    var Menu = {
        id: "menuTable",
        table: null,
        layerIndex: -1
    };


    var wdbh = "";
    var wdbt = "";
    var username = "";
    var cjrq = "";
    var jsrq = "";
    var state = "0";
    var wdzt = "";
    var crudServiceBaseUrl = "/wedding_admin/sys/sysdocument/infoBeLongTo",
        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: crudServiceBaseUrl,
                    type: "POST",
                    dataType: "json"
                },
                parameterMap: function (options, type) {

                    if (type == "read" && options.page) {

                        var datas = Hap.prepareSubmitParameter(options, type);


                        return {//分页参数
                            limit: options.pageSize,  //当前页码
                            page: options.page, //每页显示记录数

                            wdbh: wdbh,//模糊查询参数
                            wdbt: wdbt,
                            username: username,
                            cjrq: cjrq,
                            jsrq: jsrq,
                            state: state, //是否启用模糊查询状态
                            wdzt: wdzt

                        }

                    } else if (type !== "read") {

                        return Hap.prepareQueryParameter(viewModel.model.toJSON(), options);

                    }
                }
            },
            batch: true,
            serverPaging: true,
            pageSize: 10,
            schema: {
                data: function (data) {
                    return data.page.list;
                },
                total: function (data) {
                    return data.page.totalCount;
                },
                model: {
                    id: "documentId",
                    fields: {
                        create_time: {type: "date", format: "{0:yyyy-MM-dd HH:mm:ss}"}
                    }
                }
            }


        });


    var grid = $("#grid").kendoGrid({
        dataSource: dataSource,
        dataBound: function () {

            if (parent.autoResizeIframe) {
                parent.autoResizeIframe('HSP_SERVICE_INSTANCE')
            }
        },
        resizable: true,
        scrollable: true,
        navigatable: false,
        editable: false,
        selectable: 'multiple,rowbox',
        pageable: {
            pageSizes: [10, 20, 50, 100, 200, 500],
            refresh: true,
            buttonCount: 5
        },
        columns: [
            {
                field: "documentId",
                title: '文档ID',
                width: 80,

                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap;text-align: center"
                }
            },
            {
                field: "doccode",
                title: '文档编号',
                width: 80,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap;text-align: center"
                }
            },
            {
                field: "headline",
                title: '文档标题',
                width: 80,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap;text-align: center"
                }
            },
            {
                field: "creatorName",
                title: '创建人',
                width: 80,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap;text-align: center"
                }
            },
            {
                field: "delFlag",
                title: '文档状态',
                width: 80,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap;text-align: center"
                },
                template: function (dataItem) {
                    /*0:草稿
                    1:正常
                    2:待发布
                    3:失效
                    4:作废*/
                    if (JSON.stringify(dataItem.delFlag) == 1) {
                        return "正常"
                    } else if (JSON.stringify(dataItem.delFlag) == 2) {
                        return "待发布"
                    } else if (JSON.stringify(dataItem.delFlag) == 4) {
                        return "作废"
                    }
                }
            }, {
                field: "createDate",
                title: '创建日期',
                width: 80,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap;text-align: center"
                }
            }, {
                attributes: {style: "text-align:center"},
                title: '文档详情',
                command: [{
                    name: 'edit',
                    template: '<a href="javascript:void(0)" class="k-grid-edit">详情</a>',
                    click: function (e) {
                        var data = this.dataItem($(e.target).closest("tr"));
                        window.open("../sys_documents_query.html?documentId=" + data.documentId);


                    }
                }],
                width: 70,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                }
            }
        ]
    }).data("kendoGrid");


    Hap.autoResizeGrid("#grid");

    $("#btnSearch").click(function () {//查询按钮
        var s_wdbh = $("#wdbh").val();//获取  文档编号
        var s_wdbt = $("#wdbt").val();//获取 文档目录
        var s_username = $("#username").val();//获取 文档创建者
        var s_cjrq = $("#cjrq").val();//获取 创建日期
        var s_jsrq = $("#jsrq").val();//获取 结束日期
        var s_wdzt = $("#wdzt").val();//文档状态

        wdbh = s_wdbh;  //将文本传给 数据源(dataScorce)中的 demoCondiions
        wdbt = s_wdbt;
        username = s_username;
        cjrq = s_cjrq;
        jsrq = s_jsrq;
        wdzt = s_wdzt;
        state = "1"
        grid.dataSource.page(1);  //更新 Grid

    });
</script>

</body>
</html>
